<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
     * {
      margin: 0;
      padding: 0;
    }
    .tab {
      width: 590px;
      margin: 20px;
      height: 400px;
      border: 1px solid #e4e4e4;
    }

    .tab-nav {
      width: 100%;
      height: 60px;
      line-height: 60px;
      display: flex;
      justify-content: space-between;
    }
    .tab-nav h3 {
      font-size: 24px;
      font-weight: normal;
      margin-left: 20px;
    }
    .tab-nav ul {
      list-style: none;
      display: flex;
      justify-content: flex-end;
    }
    .tab-nav ul li {
      margin: 0 20px;
      font-size: 14px;
    }
    .tab-nav ul li a {
      text-decoration: none;
      border-bottom: 2px solid transparent;
      color: black;
    }
    .tab-nav ul li a.active {
      border-color: red;
      color: red;
    }
    .tab-content {
      padding: 0 16px;
    }
    img{
      width: 100%;
      height: 100%;
    }
    .tab-content .item {
      display: none;
    }
    .tab-content .item.active {
      display: block;
    }
    </style>
</head>
<body>
    <div class="tab">
    <div class="tab-nav">
      <h3>每日特价</h3>
      <ul>
        <li><a class="active" href="#">精选</a></li>
        <li><a href="#">美食</a></li>
        <li><a href="#">百货</a></li>
        <li><a href="#">个护</a></li>
        <li><a href="#">预告</a></li>
      </ul>
    </div>
    <div class="tab-content">
      <div class="item active"><img src="/study-js/作业/images/Snipaste_2025-11-02_16-16-30.png" alt="" /></div>
      <div class="item"><img src="/study-js/作业/images/Snipaste_2025-11-02_16-18-00.png" alt="" /></div>
      <div class="item"><img src="/study-js/作业/images/Snipaste_2025-11-02_16-18-00.png" alt="" /></div>
      <div class="item"><img src="/study-js/作业/images/Snipaste_2025-11-02_16-16-30.png" alt="" /></div>
      <div class="item"><img src="/study-js/作业/images/Snipaste_2025-11-02_16-18-00.png" alt="" /></div>
    </div>
  </div>
    <script>
    let als = document.querySelectorAll('.tab-nav a');
    for (let i = 0; i < als.length; i++) {
      als[i].addEventListener('mouseenter', function () {
        document.querySelector('.tab-nav .active').classList.remove('active')
        this.classList.add('active');
        document.querySelector(`.tab-content .active`).classList.remove('active');
        document.querySelector(`.item:nth-child(${i + 1})`).classList.add('active');
      });
 
    }
    </script>
</body>
</html>